/*
 * 软件著作权：北京康兰尚德数据科技有限公司
 * 项目名称：康兰数据购物中心分析平台
 *
 * NAME : StoryDaoImpl.java
 *
 * PURPOSE : 品牌故事数据库访问
 *
 * AUTHOR : EEDATA/ywb
 *
 *
 * 创建日期: 2013-11-28
 * HISTORY：
 * 变更日期 
 */
package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import pojo.EcpPpBrand;
import pojo.EcpPpStory;
import pojo.EcpPpStorycomment;
import util.HibernateUtils;

/**
 * 品牌故事数据访问层
 * 
 * @author ywb
 */

public class StoryDaoImpl {

    /**
     * 根据品牌id查询品牌信息
     */
    public EcpPpBrand selectBrand(String brandid) {// 十三、getBrandStoryInfoList接口
        Session session = null;
        Transaction ts = null;
        EcpPpBrand brand =null;
        try {
            session = HibernateUtils.getSession();
            ts = session.beginTransaction();

            brand= (EcpPpBrand) session.get(EcpPpBrand.class, brandid);

            ts.commit();

        } catch (Exception e) {
            e.printStackTrace();
            ts.rollback();
        } finally {
            HibernateUtils.closeSession(session);
        }

        return brand;
        
        
    }


    /**
     * 根据品牌id查询故事信息
     */
    @SuppressWarnings("unchecked")
    public List<EcpPpStory> selectStory(String brandid) {// 十三、getBrandStoryInfoList接口
        Session session = null;
        Transaction ts = null;
        List<EcpPpStory> list = null;
        try {
            session = HibernateUtils.getSession();
            ts = session.beginTransaction();

            Query query = session.createQuery("from EcpPpStory where brandid=?");
            query.setParameter(0, brandid);
            list = query.list();

            ts.commit();

        } catch (Exception e) {
            e.printStackTrace();
            ts.rollback();
        } finally {
            HibernateUtils.closeSession(session);
        }

        return list;

    }


    /**
     * 根据故事id查询故事评论数
     */
    @SuppressWarnings("unchecked")
    public Integer selectStoryCommentNum(Integer storyid) {// 十三、getBrandStoryInfoList接口
        Session session = null;
        Transaction ts = null;
        int num = 0;
        try {
            session = HibernateUtils.getSession();
            ts = session.beginTransaction();

            Query query = session.createQuery("from EcpPpStorycomment where storyid=?");
            query.setParameter(0, storyid);
            List<EcpPpStorycomment> list = query.list();
            num = list.size();

            ts.commit();

        } catch (Exception e) {
            e.printStackTrace();
            ts.rollback();
        } finally {
            HibernateUtils.closeSession(session);
        }

        return num;

    }
}
